package com.sinping.qh.api.app.base;

import com.sinping.qh.api.base.BaseEndPoint;
import com.sinping.qh.api.exception.HandlerException;
import com.sinping.qh.api.support.ConstEum;
import com.sinping.qh.dto.mongo.auth.UserSessionDTO;
import com.sinping.qh.service.app.login.ILoginService;
import com.sinping.qh.service.redis.RedisService;
import com.sinping.qh.utils.mapper.JsonMapper;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.Set;

/**
 * 是否登录检查放入到filter中
 * @author zhangjin
 * @create 2018/5/31
 */
@Data
public class BaseAppEndPoint extends BaseEndPoint {


    @Autowired
    private HttpServletRequest request;



    @Autowired
    RedisService redisService;


    public static final String token_name = "token";

    public static final String mPlatform = "platform";

    /***************************************************************
     ************************获取数据区********************************
     ****************************************************************/



    /**
     * 获取请求平台
     * @return
     */
    public String getRequestPlatform()
    {
        String platform = request.getHeader(mPlatform);
        return platform;
    }


    public UserSessionDTO getUserSessionDto()
    {
        String userSessionDTO=
                redisService.hgetByUserinfo(getToken());
        UserSessionDTO newUserSessionDTO=
                JsonMapper.defaultMapper().fromJson(userSessionDTO,UserSessionDTO.class);
        return newUserSessionDTO;
    }

}
